package com.guardchina.framework.mybatis.impl;

import com.guardchina.framework.mybatis.api.RoutingDataSourceStrategy;

import java.util.concurrent.ThreadLocalRandom;

/**
 * 描述：随机获取从库数据源
 *
 * @author lwb
 * @date 2019/3/22 11:05
 */
public class RandomDataSourceStrategy implements RoutingDataSourceStrategy {

    @Override
    public String deterMineSlaveDataSource(String[] slaveDataSourceKeys) {

        int i = ThreadLocalRandom.current().nextInt(slaveDataSourceKeys.length);

        return slaveDataSourceKeys[i];
    }
}
